enum Permission {
  read = 1, write = 2, delete = 4, update = 8
}

let p: Permission = Permission.read | Permission.write;

// 判断是否拥有某个权限
function hasPermission(target: Permission, per: Permission) {
  return (target & per) == per;
}

console.log(hasPermission(p, Permission.read));

// 删除某个权限
// 异或(相同取0不同取1)
// 0011
// 0001
// 0010
p = p ^ Permission.read;
console.log(hasPermission(p, Permission.read));